package com.nari.ncps.screen.service.impl.dryport;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nari.ncps.screen.entity.dryport.DryportBizmgtDay;
import com.nari.ncps.screen.mapper.dryport.DryportBizmgtDayMapper;
import com.nari.ncps.screen.service.dryport.DryportBizmgtDayService;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 路港业务管理日报表 服务实现类
 * </p>
 *
 * @author system
 * @since 2025-11-06
 */
@Service
public class DryportBizmgtDayServiceImpl extends ServiceImpl<DryportBizmgtDayMapper, DryportBizmgtDay> implements DryportBizmgtDayService {

    @Override
    public List<DryportBizmgtDay> getByDateNo(String dateNo) {
        return baseMapper.getByDateNo(dateNo);
    }

    @Override
    public List<DryportBizmgtDay> getByDateNoAndOrgCode(String dateNo, String orgCode) {
        return baseMapper.getByDateNoAndOrgCode(dateNo, orgCode);
    }

    @Override
    public List<DryportBizmgtDay> getByDateRange(String startDate, String endDate) {
        return baseMapper.getByDateRange(startDate, endDate);
    }

    @Override
    public List<DryportBizmgtDay> getLatestByOrgCode(String orgCode, Integer limit) {
        return baseMapper.getLatestByOrgCode(orgCode, limit);
    }

    @Override
    public BigDecimal getOperatingRevenue(String dateNo, String orgCode, String salesType) {
        LambdaQueryWrapper<DryportBizmgtDay> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DryportBizmgtDay::getDateNo, dateNo)
                .eq(DryportBizmgtDay::getOrgCode, orgCode)
                .eq(DryportBizmgtDay::getSalesType, salesType)
                .last("LIMIT 1");
        DryportBizmgtDay item = this.getOne(queryWrapper);
        return item != null ? item.getOperatingRevenue() : null;
    }

    @Override
    public BigDecimal getPortcoalSalesVolume(String dateNo, String orgCode, String salesType) {
        LambdaQueryWrapper<DryportBizmgtDay> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DryportBizmgtDay::getDateNo, dateNo)
                .eq(DryportBizmgtDay::getOrgCode, orgCode)
                .eq(DryportBizmgtDay::getSalesType, salesType)
                .last("LIMIT 1");
        DryportBizmgtDay item = this.getOne(queryWrapper);
        return item != null ? item.getPortcoalSalesVolume() : null;
    }

    @Override
    public BigDecimal getPortoperationVolume(String dateNo, String orgCode, String salesType) {
        LambdaQueryWrapper<DryportBizmgtDay> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DryportBizmgtDay::getDateNo, dateNo)
                .eq(DryportBizmgtDay::getOrgCode, orgCode)
                .eq(DryportBizmgtDay::getSalesType, salesType)
                .last("LIMIT 1");
        DryportBizmgtDay item = this.getOne(queryWrapper);
        return item != null ? item.getPortoperationVolume() : null;
    }
}

